﻿using System;
using FluentValidation;
using FluentValidation.TestHelper;
using GiveAQuiz.Web.Models;
using GiveAQuiz.Web.Validation;
using NUnit.Framework;

namespace GiveAQuiz.Web.Tests.Validation
{
  [TestFixture]
  public class StartQuizValidatorTest
  {
    public IValidator<StartQuizViewModel> Validator
    {
      get; private set;
    }

    [TestFixtureSetUp]
    public void SetUpFixture()
    {
      Validator = new StartQuizValidator();
    }

    [Test]
    public void RuleFor_QuizDefinitionID_cannot_be_zero()
    {
      var model = new StartQuizViewModel {QuizDefinitionId = 0};
      Validator.ShouldHaveValidationErrorFor(sq => sq.QuizDefinitionId, model);
    }

    [Test]
    public void RuleFor_QuizName_cannot_be_null()
    {
      var model = new StartQuizViewModel { QuizName = null };
      Validator.ShouldHaveValidationErrorFor(sq => sq.QuizName, model);
    }

    [Test]
    public void RuleFor_QuizName_cannot_be_empty()
    {
      var model = new StartQuizViewModel { QuizName = String.Empty };
      Validator.ShouldHaveValidationErrorFor(sq => sq.QuizName, model);
    }

    [Test]
    public void RuleFor_Passphrase_cannot_be_null()
    {
      var model = new StartQuizViewModel { Passphrase = null };
      Validator.ShouldHaveValidationErrorFor(sq => sq.Passphrase, model);
    }

    [Test]
    public void RuleFor_Passphrase_cannot_be_empty()
    {
      var model = new StartQuizViewModel { Passphrase = String.Empty };
      Validator.ShouldHaveValidationErrorFor(sq => sq.Passphrase, model);
    }

    [Test]
    public void RuleFor_StartDate_cannot_be_DateTime_MinValue()
    {
      var model = new StartQuizViewModel { StartDate =  DateTime.MinValue };
      Validator.ShouldHaveValidationErrorFor(sq => sq.StartDate, model);
    }

    [Test]
    public void RuleFor_EndDate_cannot_be_DateTime_MinValue()
    {
      var model = new StartQuizViewModel { EndDate = DateTime.MinValue };
      Validator.ShouldHaveValidationErrorFor(sq => sq.EndDate, model);
    }

    [Test]
    public void RuleFor_EndDate_cannot_be_before_StartDate()
    {
      var model = new StartQuizViewModel { EndDate = DateTime.Now, StartDate = DateTime.Now.AddDays(1) };
      Assert.IsTrue(model.EndDate < model.StartDate);
      Validator.ShouldHaveValidationErrorFor(sq => sq.EndDate, model);
    }
    
  }
}
